import tool from "@/common/tool.js"
const FM = null
const Formatter = function() {
  this.cache = JSON.parse(tool.getStorage('dictionaryData'));
};
Formatter.prototype.switchName = function(name, key) { //字段格式化查询
  let formatter = this.cache[name];
  return this.switchFormatter(formatter, key);
};
Formatter.prototype.switchFormatter = function(formatter, key) { //字段格式化查询
  if (!formatter) return key;
  if (!key) return '-';
  if (formatter && formatter.length <= 0) return key;
  //let reg = new RegExp(String(key));
  for (let i = 0; i < formatter.length; i++) {
    if (String(key) === String(formatter[i].key)) {
      return formatter[i].value;
    }
  }
  return key;
};
Formatter.prototype.formatArea = function(min, max) { //建面格式化
  if (min == null && max == null) {
    return '建面待定'
  } else {
    if (min == null) {
      return `建面约${max}㎡`
    } else if (max == null) {
      return `建面约${min}㎡`
    } else {
      return `建面${min}-${max}㎡`
    }
  }
};
Formatter.prototype.formatTotalPrice = function(min, max) { //总价格式化
  if (min == null && max == null) {
    return '总价待定'
  } else {
    if (min == null) {
      return `总价约${max}万`
    } else if (max == null) {
      return `总价约${min}万`
    } else {
      return `总价${min}-${max}万`
    }
  }
};
Formatter.prototype.AveragePrice = function(type, min) { //均价格式化
  if (min == null) {
    return '均价待定'
  } else {
    if (type == 1) {
      return `${min}元/㎡`
    } else {
      return `${min}元/㎡起`
    }
  }
};
Formatter.prototype.formatMinMax = function(min, max, unit) { //最大最小值格式化
  if (min == null && max == null) {
    return '-'
  } else {
    if (min == null) {
      return `${max}${unit}`
    } else if (max == null) {
      return `${min}${unit}`
    } else {
      return `${min}${unit}~${max}${unit}`
    }
  }
};
Formatter.prototype.toFixedformarter = function(val, bit) { //均价格式化
  let num = ''
  if (bit) {
    num = Number(val).toFixed(bit)
  } else {
    num = parseInt(value).toString();
  }
  return num - 0
};
Formatter.prototype.optLocation = function() {
  return [{
    key: '1',
    value: '1',
    disabled: false
  },
  {
    key: '2',
    value: '2',
    disabled: false
  }, {
    key: '3',
    value: '3',
    disabled: false
  },
  {
    key: '8',
    value: '8',
    disabled: false
  },
  {
    disabled: true,
    key: '9',
    value: ''
  },
  {
    key: '4',
    value: '4',
    disabled: false
  },
  {
    key: '7',
    value: '7',
    disabled: false
  },
  {
    key: '6',
    value: '6',
    disabled: false
  },
  {
    key: '5',
    value: '5',
    disabled: false
  }]
};
export default new Formatter();